package com.assignwork.util;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 去掉小数位
 *
 * @author ：dujianyu
 * @since ：Created in 2024/4/15 16:23
 */
public class BigDecimalSerializer extends JsonSerializer<BigDecimal> {

    public BigDecimalSerializer() {
    }

    @Override
    public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value != null) {
            BigDecimal number = value.stripTrailingZeros();
            gen.writeNumber(number);
        } else {
            gen.writeNumber(value);
        }

    }

}
